package edu.uci.ics.ai.maze.models;

import java.text.MessageFormat;

public class Vertex implements Cloneable {

  private final int x;  // x-coordinate
  private final int y;  // y-coordinate
  private Polygon polygon;  // the polygon index that this vertex belongs to

  public Vertex() {
    this(0, 0);
  }

  /**
   * copy constructor
   * @param v
   */
  public Vertex(final Vertex v) {
    this(v.x, v.y, v.polygon);
  }

  public Vertex(int x, int y) {
    this(x, y, null);
  }

  public Vertex(int x, int y, Polygon polygon) {
    this.x = x;
    this.y = y;
    this.polygon = polygon;
  }

  @Override
  public Object clone() throws CloneNotSupportedException {
    return super.clone();
  }

  @Override
  public String toString() {
    return MessageFormat.format("({0},{1},{2})", getX(), getY(), getPolygon());
  }

  public final int getX() {
    return x;
  }

  public final int getY() {
    return y;
  }

  public final Polygon getPolygon() {
    return polygon;
  }

  public void setPolygon(Polygon n) {
    polygon = n;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (!(this instanceof Vertex)) {
      return false;
    }
    final Vertex other = (Vertex) obj;
    if (this.x != other.x) {
      return false;
    }
    if (this.y != other.y) {
      return false;
    }
    return true;
  }

  @Override
  public int hashCode() {
    int hash = 7;
    hash = 17 * hash + this.x;
    hash = 17 * hash + this.y;
    return hash;
  }
  
}
